<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>投票</title>
    <style>
        .btn,.btn1,.btn2{
            display: inline-block;
            width: 100px;
            height: 50px;
            background-color: aqua;
        }
    </style>
</head>
<body>
<button class="btn">胡歌</button>
<span class="spa">0</span>

<br>
<button class="btn1">小川</button>
<span class="spa1">0</span>
<br>
<button class="btn2">地瓜</button>
<span class="spa2">0</span>
<br>
<script>
    var x = 0;//外部定义变量x
    var btn=document.getElementsByClassName("btn")[0];
    btn.addEventListener('click',function () {
        x++;//记录被点击次数
        document.getElementsByClassName('spa')[0].innerHTML = x;
        }
    )
    var y = 0;
    var btn=document.getElementsByClassName("btn1")[0];
    btn.addEventListener('click',function () {
            y++;
            document.getElementsByClassName('spa1')[0].innerHTML = y;
        }
    )
    var z = 0;
    var btn=document.getElementsByClassName("btn2")[0];
    btn.addEventListener('click',function () {
            z++;
            document.getElementsByClassName('spa2')[0].innerHTML = z;
        }
    )



</script>
</body>
</html>